package sandbox;

import java.util.Scanner;
import java.net.DatagramSocket;
import java.net.DatagramPacket; 
import java.net.SocketException;

public class UdpSendDebuger
{
	public static void main(String[] args)
	{
		String cmd = "default";
		Scanner scan = new Scanner(System.in);
		byte[] b = new byte[100]; 
		String host = new String();
		String msg = new String(); 
		int port; 
		DatagramPacket p; 
		DatagramSocket s;
		
		while(!cmd.equals("end"))
		{
			cmd = scan.next();
			
			if (cmd.trim().equals("send"))
			{
				System.out.print("host>");
				cmd = scan.next(); 
				host = new String(cmd);
				System.out.print("port>");
				port = scan.nextInt();
				System.out.print("message>");
				msg = scan.next();
				
				try
        {
					p = new DatagramPacket(msg.getBytes(), msg.length());
	        s = new DatagramSocket();
	        s.send(p); 
        } catch (Exception e)
        {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
        } 
				
			}
			else if (cmd.trim().equals("end"))
			{
				System.out.println("bye");
			}
			else
			{
				System.out.println("Wrong command");
			}
		}
	}
}
